//
//  NSMutableAttributedString+HACShield.m
//  HACRouter
//
//  Created by Chengjie on 2019/5/22.
//

#import "NSMutableAttributedString+HACShield.h"
#import "NSObject+HACSwizzling.h"

@implementation NSMutableAttributedString (HACShield)

/**
 == > NSConcreteMutableAttributedString
 */
+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        hac_swizzleInstanceMethod(hac_getClass(@"NSConcreteM", @"utableAttributedString"), @selector(initWithString:), @selector(hac_initWithString:));
        hac_swizzleInstanceMethod(hac_getClass(@"NSConcreteM", @"utableAttributedString"), @selector(initWithString:attributes:), @selector(hac_initWithString:attributes:));
        hac_swizzleInstanceMethod(hac_getClass(@"NSConcreteM", @"utableAttributedString"), @selector(initWithAttributedString:), @selector(hac_initWithAttributedString:));
    });
}


- (instancetype)hac_initWithString:(NSString *)aString {
    if (aString && [aString isKindOfClass:NSString.class]) {
        return [self hac_initWithString:aString];
    }
    return [self hac_initWithString:@""];
}

- (instancetype)hac_initWithString:(NSString *)str attributes:(nullable NSDictionary<NSAttributedStringKey, id> *)attrs {
    if (str) {
        return [self hac_initWithString:str attributes:attrs];
    }
    
    return [self hac_initWithString:@"" attributes:attrs];
}

- (instancetype)hac_initWithAttributedString:(NSAttributedString *)attrStr {
    if (attrStr && [attrStr isKindOfClass:NSAttributedString.class]) {
        return [self hac_initWithAttributedString:attrStr];
    }
    NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:@""];
    return [self hac_initWithAttributedString:attributedString];
}

@end
